<html>
<head><meta charset="utf-8"><title>match_[q]path is bad? · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html">match_[q]path is bad?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233215638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233215638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233215638">(Apr 05 2021 at 19:10)</a>:</h4>
<p>We use <code>match_path</code> and <code>match_qpath</code> a lot. It only matches against the part of the path that is in the usage, not the full imported path. So...isn't this really bad? Here is an example of a false positive caused by this (<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=694cca59bc8c4f6a6d20d1219c4751e6">playground</a>). We have <code>match_def_path</code> which works more precisely. Should we not accept more usages of <code>match_path</code> and <code>match_qpath</code> in PRs? I think we have a lot of paths that would need to be adjusted to work with <code>match_def_path</code>. And maybe all the std paths could be changed to core?</p>



<a name="233215948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233215948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233215948">(Apr 05 2021 at 19:13)</a>:</h4>
<p>Of course it would be a waste to migrate existing code to <code>match_def_path</code> when we are also migrating to diagnostic items.</p>



<a name="233218403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233218403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xFrednet <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233218403">(Apr 05 2021 at 19:33)</a>:</h4>
<p><code>match_path</code> definitely as some quirks. I've used <code>walk_ptrs_ty_depth</code> to get the full original path and that seems to be working fine but might be some overhead. It was also not a conscious decision and more a copy of another lint.</p>
<p>Isn't such a case exactly what diagnostic items are meant for? I only know the issue <a href="https://github.com/rust-lang/clippy/issues/5393">clippy#5393</a> but never quite understood the context tbh <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="233219021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233219021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233219021">(Apr 05 2021 at 19:39)</a>:</h4>
<p>Diagnostic items are a neat solution, but not a strictly needed solution since we have match_def_path. I believe the reason for diagnostic items in a word is maintainability.</p>



<a name="233219230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233219230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xFrednet <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233219230">(Apr 05 2021 at 19:41)</a>:</h4>
<p>Is the usage somewhere documented? I know that the lint's should be migrated but I've never seen a guide or at least an example <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="233219855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233219855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233219855">(Apr 05 2021 at 19:46)</a>:</h4>
<p>Just look for <code>tcx.is_diagnostic_item</code> which takes a name Symbol. The name corresponds to <code>#[rustc_diagnostic_item = "name"]</code> on the item definition, generally in std.</p>



<a name="233221764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233221764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xFrednet <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233221764">(Apr 05 2021 at 20:01)</a>:</h4>
<p>I'll put that on my TODO list. So, that would solve the problems of <code>match_path</code> right? <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="233281791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/match_%5Bq%5Dpath%20is%20bad%3F/near/233281791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Wright <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/match_.5Bq.5Dpath.20is.20bad.3F.html#233281791">(Apr 06 2021 at 08:12)</a>:</h4>
<p>Yes. It's bad.  +1 for removing those methods completely.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>